<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <script type="text/javascript">
        var app = document.getElementById("app");
        var oUl = document.createElement("ul"); 
        
        for(var i=0;i<10;i++) {
            var oLi = document.createElement("li");
            oLi.innerText = '列表第'+(i+1)+'项';
            oUl.appendChild(oLi);
        }
        
        app.appendChild(oUl);
        var items = document.getElementsByTagName('li');
        oUl.onclick = function(ev){
            var ev = ev || window.event,
                target = ev.target || ev.srcElement,
                targetName = target.nodeName.toLowerCase();
                if(targetName === 'li'){
                    // var index = Array.from(items).indexOf(target); // 将元素类数组转为数组
                    // var index = [].indexOf.call(items,target); // call 改变 指向
                    var index = [...items].indexOf(target); // 扩展运算符转为数组 
                    console.log(target.innerText);
                    console.log(index);
                }
        }
    </script>
</body>

</html>